{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# geohash示例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pygeohash"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 设置第五级编码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'wx4g5'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pygeohash.encode(39.91,116.52,5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 从第一级开始编码"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 一直到第六级都是一样的，第七级才开始不同\n",
    "### 表示了152m* 152m格子的时候，这两个点不在同一个格网里面了"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i = 1:  [w] -> [w]\n",
      "i = 2:  [wx] -> [wx]\n",
      "i = 3:  [wx4] -> [wx4]\n",
      "i = 4:  [wx4g] -> [wx4g]\n",
      "i = 5:  [wx4g5] -> [wx4g5]\n",
      "i = 6:  [wx4g59] -> [wx4g59]\n",
      "i = 7:  [wx4g598] -> [wx4g59b]\n",
      "i = 8:  [wx4g5984] -> [wx4g59b8]\n",
      "i = 9:  [wx4g59842] -> [wx4g59b8r]\n",
      "i = 10:  [wx4g59842j] -> [wx4g59b8r2]\n",
      "i = 11:  [wx4g59842jd] -> [wx4g59b8r2h]\n",
      "i = 12:  [wx4g59842jdu] -> [wx4g59b8r2h9]\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,13):\n",
    "    print(\"i = {0}:  [{1}] -> [{2}]\".format(i,pygeohash.encode(39.911,116.521,i),\n",
    "                                            pygeohash.encode(39.912,116.522,i)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 可以通过decode进行解码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(39.911, 116.521)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pygeohash.decode(\"wx4g59842jdu\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
